﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace l1cs.server.serverpackets
{
    class S_ServerMessage : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_ServerMessage ).FullName );

        public const int NO_PLEDGE = 208;

        public const int CANNOT_GLOBAL = 195;

        public const int CANNOT_BOOKMARK_LOCATION = 214;

        public const int USER_NOT_ON = 73;

        public const int NOT_ENOUGH_MP = 278;

        public const int YOU_FEEL_BETTER = 77;

        public const int YOUR_WEAPON_BLESSING = 693;

        public const int YOUR_Are_Slowed = 29;

        //private byte[] _byte = null;

        public S_ServerMessage( int type )
        {
            buildPacket( type, null, null, null, null, null, 0 );
        }

        public S_ServerMessage( int type, String msg1 )
        {
            buildPacket( type, msg1, null, null, null, null, 1 );
        }

        public S_ServerMessage( int type, String msg1, String msg2 )
        {
            buildPacket( type, msg1, msg2, null, null, null, 2 );
        }

        public S_ServerMessage( int type, String msg1, String msg2, String msg3 )
        {
            buildPacket( type, msg1, msg2, msg3, null, null, 3 );
        }

        public S_ServerMessage( int type, String msg1, String msg2, String msg3,
                String msg4 )
        {
            buildPacket( type, msg1, msg2, msg3, msg4, null, 4 );
        }

        public S_ServerMessage( int type, String msg1, String msg2, String msg3,
                String msg4, String msg5 )
        {

            buildPacket( type, msg1, msg2, msg3, msg4, msg5, 5 );
        }

        private void buildPacket( int type, String msg1, String msg2, String msg3,
                String msg4, String msg5, int check )
        {

            writeC( Opcodes.S_OPCODE_SERVERMSG );
            writeH( type );

            if ( check == 0 )
            {
                writeC( 0 );
            }
            else if ( check == 1 )
            {
                writeC( 1 );
                writeS( msg1 );
            }
            else if ( check == 2 )
            {
                writeC( 2 );
                writeS( msg1 );
                writeS( msg2 );
            }
            else if ( check == 3 )
            {
                writeC( 3 );
                writeS( msg1 );
                writeS( msg2 );
                writeS( msg3 );
            }
            else if ( check == 4 )
            {
                writeC( 4 );
                writeS( msg1 );
                writeS( msg2 );
                writeS( msg3 );
                writeS( msg4 );
            }
            else
            {
                writeC( 5 );
                writeS( msg1 );
                writeS( msg2 );
                writeS( msg3 );
                writeS( msg4 );
                writeS( msg5 );
            }
        }

        override
        public byte[] getContent()
        {
            return _bao.ToArray();
        }

        override
        public String getType()
        {
            return "[S] S_ServerMessage";
        }
    }
}
